package TestExercises01;

//数字解密————（结合test06和test07）
public class test08 {
    public static void main(String[] args) {
        int number = 8346;
        int number1 = number;
        int number2 = number;
        int count = 0;
        while (number1 != 0) {
            number1 = number1 / 10;
            count++;
        }

        int[] arr = new int[count];
        //将整数添加到数组中
        for (int i = arr.length - 1; number2 != 0; i--) {
            arr[i] = number2 % 10;
            number2 = number2 / 10;
        }

        System.out.print("数组反转前的元素为：");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }

        System.out.println();
        System.out.print("数组反转后的元素为：");
        for (int i = 0, j = arr.length - 1; i < j; i++, j--) {
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }

        System.out.println();
        System.out.print("数组破解余10操作后的元素为：");
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] >= 0 && arr[i] <= 4) {
                arr[i] = arr[i] + 10;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }

        System.out.println();
        System.out.print("数组破解加5操作后的元素为：");
        for (int i = 0; i < arr.length; i++) {
            arr[i] = arr[i] - 5;
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }

        System.out.println();
        int result = 0;
        for (int i = 0; i < arr.length; i++) {
            result = result * 10 + arr[i];
        }
        System.out.println("最终解密的结果为：" + result);
    }
}
